package com.yunhe.sms.dao.activite.impl;

import com.yunhe.commens.dao.impl.BaseDaoImpl;
import com.yunhe.commens.dto.Pagedao;
import com.yunhe.sms.dao.activite.VoteDao;
import com.yunhe.sms.entity.activity.Vote;

import java.util.List;

/**
 * @author LeiPeifeng
 * @version V1.0
 * @date 2017/10/30 0030 18:46
 * @Description: 实现投票类的接口
 */
public class VoteDaoImpl extends BaseDaoImpl<Vote> implements VoteDao {

    @Override
    public Long  add(Vote vote) {
        String sql=" insert into vote(title,banner,begin_time,end_time,status,deleted,creat_time) values(?,?,?,?,?,0,now()) ";
        Long id = super.insert ( sql, vote.getTitle (), vote.getBanner (), vote.getBeginTime (), vote.getEndTime (), vote.getStatus () );
        return id;
    }

    @Override
    public void deleted(Long id) {
        String sql = " update vote set deleted=1 where id=?";
        super.cut ( sql,id );
    }

    @Override
    public void update(Vote vote) {
        String sql = " update vote set title=?,banner=?,begin_time=?,end_time=?,status=? where id=?";
        super.cut ( sql,vote.getTitle (),vote.getBanner (),vote.getBeginTime (),vote.getEndTime (),vote.getStatus (),vote.getId () );
    }

    @Override
    public Vote findId(Long id) {
        String sql=" select id,title,sum,banner,begin_time beginTime,end_time endTime,status from vote where deleted=0 and id=? ";
        return super.quaryOne ( sql,id );
    }

    @Override
    public List<Vote> find() {
        String sql=" select id,title,sum,banner,begin_time begin_time beginTime,end_time endTime,status from vote where deleted=0 ";
        return super.quaryList ( sql );
    }

    @Override
    public Pagedao<Vote> page(int offset, int limit) {
        String listsql=" select id,sum,title,banner,begin_time beginTime,end_time endTime,status from vote where deleted=0 ";
        String countsql=" select count(*) from vote where deleted=0 ";
        Pagedao<Vote> votePagedao = super.quaryPage ( listsql, countsql, offset, limit );
        return votePagedao;
    }

    @Override
    public void upstatus(Long id) {
        String sql =" update vote set status=1 where id=? ";
        super.cut ( sql,id );
    }

}
